<?php
namespace Admin\Controller;
use Think\Controller;
use Common\LoginBaseController;
use Common\Common\Log;
class LoginController extends LoginBaseController {
    public function index(){
        $this->display();
    }
    //提交登录信息
    public function dologin()
    {
        if(I('post.username') && I('post.password') && I('post.captcha')){
            $username=I('post.username');//用户名
            $password=I('post.password');//密码
            $captcha=I('post.captcha');//验证码
            //校验验证码
            $verify = new \Think\Verify ();
            if(!$verify->check($captcha)){
                $this->showMsg('验证码错误!','error','index');
            }
            if($re=M('Admin')->where('status="1" AND username="%s" AND password="%s"',$username,$this->encryption($password))->find()){
                $userInfo=array(
                    'id'=>$re['id'],
                    'userName'=>$re['username'],
                );
                //获取用户权限
                $auth = $this->getUserAuth( $userInfo );
                $userInfo['auth'] = $auth;
                //记录用户登录信息
                session('user',$userInfo);
                $content=$re['username'].'登陆后台';
                Log::write2($content);
                $this->showMsg('亲爱的 '.$re['username'].' 用户,欢迎回来！','success','/Admin/Index/index');
            }else{
                $this->showMsg('用户名或密码错误！请重新登录！','error','index');
            }
        }else{
            if(!I('post.username')){
                $msg='用户名不能为空!';
            }else{
                $msg='密码不能为空!';
            }
            $this->showMsg($msg,'warning','index');
        }
    }

     //验证码
    public function verifyImg()
    {
        ob_clean();
        $config =    array(
            'fontSize'    =>    30,    // 验证码字体大小
             'length'      =>    4,     // 验证码位数
              'useNoise'    =>    true, // 关闭验证码杂点
             );
        $verify = new \Think\Verify ( $config );
        $verify->entry ();
    }
}